package com.bawei.module_moto_circle.ui

import com.bawei.lib_common.base.BaseViewModel
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.RequestEvent
import com.bawei.lib_common.base.state.Success
import com.bawei.module_moto_circle.model.MotoCircleNavigationEnum
import com.bawei.module_moto_circle.model.MotoCircleNavigationItem
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject

/**
 *作者：lxy
 *功能:
 *时间：2025/5/29
 */
@HiltViewModel
class MotoCircleViewModel @Inject constructor(private val mRepository: MotoCircleRepository) :
    BaseViewModel() {

    val mNavigationItem = mutableListOf<MotoCircleNavigationItem>() //tab数据
    private val _navigationState = MutableStateFlow<RequestEvent>(Loading) //tab状态

    val navigationState
        get() = _navigationState.asStateFlow()

    /** 获取固定的导航栏 */
    fun getFixedNavigationItem() {
        execute(
            action = mRepository.navigationItem(),
            onStart = {
                _navigationState.value = Loading
            },
            onError = {
                _navigationState.value = Failed(it)
            },
            onFinish = {
                mNavigationItem.clear()
                mNavigationItem.addAll(it.data)
                _navigationState.value = Success

            }
        )


    }
}